/*
 * ServerSocketForClient.h
 *
 *  Created on: 2013-3-14
 *      Author: song
 */

#ifndef SVRSOCKET4USR_H_
#define SVRSOCKET4USR_H_
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>

#include <netinet/in.h>
#include <arpa/inet.h>

#include <net/if.h>
#include <netinet/tcp.h>

#include <sys/time.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <vector>

#include "iostream"
#include "cmd.h"
#include "types.h"
using namespace std;

#define AGENT_PORT 60003    /*服务器接收数据端口号 */

class TcpServer {
public:
	 //打开服务端口,等待连接
	TcpServer();
	~TcpServer(){};
	int  StartSvr();   //启动命令端口服务
	void StopSvr();    //停止命令端口服务


	int Write(int fd,unsigned char* buf,int len);
	int Read(int fd,unsigned char* buf,int len,double timeout);
	int ParseAndAnswerCmd(int fd,uint8 *pBuf,int iLen);
	int SendCmd(int fd,uint8 *pBuf,int iLen);

#if 0
	bool CheckCmd(Cmd_t &cmd);

	int RecCmd(int fd,Cmd_t &cmd);
	int RecCmd(int fd,DevInfo_t &devInfo);
	int RecCmd(int fd,u32Value_t &value);
#endif


#if 0
	int SendCmd(int fd,Hu32Value_t &send);
	int AnswerErr(int fd,uint16 cmd,int err);
#endif


	int  m_ListenSockFd;  //侦听端口
	int  m_ClientSockFd;  //客户端口

	char m_sClientIP[20];  //用户软件IP
	fd_set m_readfds;


private:
	pthread_t m_pthServer;

};

#endif /* USRSVRSOCKET_H_ */
